package com.pattern.bulider;

import lombok.Data;

@Data
class ComputerOne {
    private String cpu;
    private String screen;
    private String memory;
    private String mainboard;

    public ComputerOne() {
        throw new RuntimeException("can't init");
    }

    private ComputerOne(BuilderOne builder) {
        this.cpu = builder.cpu;
        this.screen = builder.screen;
        this.memory = builder.memory;
        this.mainboard = builder.mainboard;

    }

    static class BuilderOne {
        private String cpu;
        private String screen;
        private String memory;
        private String mainboard;

        public BuilderOne cpu(String val) {
            cpu = val;
            return this;
        }
        public BuilderOne screen(String val) {
            screen = val;
            return this;
        }
        public BuilderOne memory(String val) {
            memory = val;
            return this;
        }
        public BuilderOne mainboard(String val) {
            mainboard = val;
            return this;
        }
        public ComputerOne build() {
            return new  ComputerOne(this);
        }
    }
}

public class BuilderTest1 {
    public static void main(String[] args) {
        // Builder 模式
        ComputerOne computerOne = new ComputerOne.BuilderOne()
                .cpu("cpu")
                .screen("screen")
                .memory("memory")
                .mainboard("mainboard")
                .build();
        System.out.println(computerOne);
    }
}
